
#进入初始目录~
cd opt/lagou/servers
#前提步骤 安装配置 节点
mkdir -p redis-cluster
# redis-cluster 目录下创建3master3slave
mkdir -p master1
mkdir -p master2
mkdir -p master3
mkdir -p slave1
mkdir -p slave2
mkdir -p slave3
#servers下有 
cd /opt/lagou/servers/redis-5.0.5/src
#在src编译
make install PREFIX=/opt/lagou/servers/redis-cluster/master1/ 
make install PREFIX=/opt/lagou/servers/redis-cluster/master2/
make install PREFIX=/opt/lagou/servers/redis-cluster/master3/
make install PREFIX=/opt/lagou/servers/redis-cluster/slave3/
make install PREFIX=/opt/lagou/servers/redis-cluster/slave2/
make install PREFIX=/opt/lagou/servers/redis-cluster/slave1/
#复制 /opt/lagou/servers/redis-5.0.5/redis.conf 
cp /opt/lagou/servers/redis-5.0.5/redis.conf /opt/lagou/servers/redis-cluster/master1/bin/
#修改 /opt/lagou/servers/redis-cluster/master1/bin/redis.conf
# daemonize yes
# protected-mode no
#port 7001   
# 注释 #bind 127.0.0.1
# cluster-enabled yes
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/master2/bin/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/master2/bin/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/slave1/bin/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/slave2/bin/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/slave3/bin/
# 修改redis.conf  master2 7002  master3 7003  slave1 7004 slave2 7005 slave3 7006

#启动 6个节点
cd  /opt/lagou/servers/redis-cluster
#开启服务
./start.sh
./redis-cli --cluster create 192.168.80.120:7001 linux01:7002 linux01:7003 linux01:7004 linux01:7005 linux01:7006 --cluster-replicas 1
#随机进入某主节点 
cd /opt/lagou/servers/redis-cluster/master1/bin
#启动客户端
./redis-cli -h linux01 -p 7001 -c
 cluster nodes
#1721f804dba54cb24f4b6bde3efa328c818d59d5 192.168.80.120:7003@17003 master - 0 1610504926595 3 connected 10923-16383
#e5319ab88b419c06fc66a37a461b6c50a7ddbdcf 192.168.80.120:7006@17006 slave 1721f804dba54cb24f4b6bde3efa328c818d59d5 0 1610504930627 3 connected
#b7f2cc74e088d1dad4d2862138523c350af391bf 192.168.80.120:7002@17002 myself,master - 0 1610504929000 2 connected 5461-10922
#60974a3a165a86563804eb336b64a48041f0e070 192.168.80.120:7004@17004 slave 83eaa15d75ac30e5befab747fdac757c3e56e16b 0 1610504929000 1 connected
#83eaa15d75ac30e5befab747fdac757c3e56e16b 192.168.80.120:7001@17001 master - 0 1610504930000 1 connected 0-5460
#6558f30f4e6e358b9d69711904c49f3bd374d4b4 192.168.80.120:7005@17005 slave b7f2cc74e088d1dad4d2862138523c350af391bf 0 1610504929621 2 connected
#slave3 7006  是 master3 7003 的从节点
#slave1 7004 是 master1 7001 从节点
#slave2 7005 是 master2 7002 的从节点
#退出客户端
exit
#########################################################
#添加节点
cd  /opt/lagou/servers/redis-cluster
mkdir -p master4
mkdir -p slave4
#安装主master4节点 slave4节点
cd /opt/lagou/servers/redis-5.0.5/src
make install PREFIX=/opt/lagou/servers/redis-cluster/master4/
make install PREFIX=/opt/lagou/servers/redis-cluster/slave4/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/master4/bin/
cp /opt/lagou/servers/redis-cluster/master1/bin/redis.conf /opt/lagou/servers/redis-cluster/salve4/bin/
#修改msater4 端口 7008 
vim  /opt/lagou/servers/redis-cluster/master4/bin/redis.conf
vim  /opt/lagou/servers/redis-cluster/slave4/bin/redis.conf
#添加主从关系
cd /opt/lagou/servers/redis-cluster/master1/bin/
#将master1 7008 加入 集群中 第二个参数 192.168.80.120:7001 为任意可用节点
./redis-cli --cluster add-node linux01:7008 192.168.80.120:7001
# 最后输出 [OK] New node added correctly. 表示成功
#查看主节点 mster4 id 
./redis-cli -c -p 7001 cluster nodes|grep master
# 2fb63f628c677e9fbe2c6147c1151897dc775da1 192.168.80.120:7008@17008 master - 0 1610506021000 7 connected

#添加从节点 将slave4 7009 添加到 msater4 7008
./redis-cli --cluster add-node linux01:7009 192.168.80.120:7008 --cluster-slave 2fb63f628c677e9fbe2c6147c1151897dc775da1
#启动客户端查看
./redis-cli -h linux01 -p 7001 -c
 cluster nodes
 
#2fb63f628c677e9fbe2c6147c1151897dc775da1 192.168.80.120:7008@17008 master - 0 1610506144000 7 connected
#6558f30f4e6e358b9d69711904c49f3bd374d4b4 192.168.80.120:7005@17005 slave b7f2cc74e088d1dad4d2862138523c350af391bf 0 1610506144737 5 connected
#83eaa15d75ac30e5befab747fdac757c3e56e16b 192.168.80.120:7001@17001 myself,master - 0 1610506143000 1 connected 0-5460
#9a7b9f38345904ba00a6692ba3df30cba572c9a8 192.168.80.120:7009@17009 slave 2fb63f628c677e9fbe2c6147c1151897dc775da1 0 1610506146752 7 connected
#60974a3a165a86563804eb336b64a48041f0e070 192.168.80.120:7004@17004 slave 83eaa15d75ac30e5befab747fdac757c3e56e16b 0 1610506142000 4 connected
#1721f804dba54cb24f4b6bde3efa328c818d59d5 192.168.80.120:7003@17003 master - 0 1610506145744 3 connected 10923-16383
#b7f2cc74e088d1dad4d2862138523c350af391bf 192.168.80.120:7002@17002 master - 0 1610506143730 2 connected 5461-10922
#e5319ab88b419c06fc66a37a461b6c50a7ddbdcf 192.168.80.120:7006@17006 slave 1721f804dba54cb24f4b6bde3efa328c818d59d5 0 1610506145000 6 connected

#添加主从成功
